package Datastruct.Queue;


/**
 * 使用数组实现队列
 */
public class ArrqyQueue {

    private  int maxsize;  //队列长度
    private  int[] arrys;  //存储队列元素

    private  int  frontpoint=-1;
    private  int rearpoint=-1;

    public ArrqyQueue(int maxsize) {
        this.maxsize = maxsize;
        arrys=new int[maxsize];
    }

    //判断队列是否为空

    public    boolean  isEmpty(){
        if(frontpoint==rearpoint){
            System.out.println("队列为空。。。。。");
            return  true;
        }
        return false;
    }
    //判断队列是否满
    public boolean  isFull(){
        if(rearpoint==maxsize-1){
            System.out.println("队列已满。。。");
            return  true;
        }
        return false;
    }

    //添加元素
    public  void   add(int entity){
        if(isFull()){
            System.out.println("队列已满。。。。");
        }
        rearpoint++;
        arrys[rearpoint]=entity;
    }

    //删除元素
    public  int  delete(){
        if(isEmpty()){
            System.out.println("队列为空");
        }
       frontpoint++;
        return arrys[frontpoint];
    }

    //返回队头元素
    public  int gethead(){
        if(isEmpty()){
            System.out.println("队列为空。。。");
        }
        return arrys[frontpoint+1];
    }
    //返回队列全部元素
    public   void  getAll(){
        if(isEmpty()){
            System.out.println("队列为空。。。。。。");
        }
        for(int i=0;i<arrys.length;i++){
            System.out.printf("arrys[%d]=%d\n",i,arrys[i]);
        }
    }
}
